#include "sock5clientmgr.hpp"

namespace oraysock5 {

void Sock5ClientMgr::add(int k, std::shared_ptr<Sock5Client> v)
{
    clis_.insert({ k, v });
}

void Sock5ClientMgr::remove(int k)
{
    clis_.erase(k);
}

std::shared_ptr<Sock5Client> Sock5ClientMgr::find(int k)
{
    auto it = clis_.find(k);
    if (it == clis_.end()) {
        return nullptr;
    }
    return it->second;
}

void Sock5ClientMgr::foreach_clis(std::function<void(int, std::shared_ptr<Sock5Client>)> cb) const
{
    for (auto& it : clis_) {
        cb(it.first, it.second);
    }
}
}
